package cn.sc.summer.auth.filter.wrapper;

import cn.sc.summer.exception.util.HttpHelper;
import cn.sc.summer.exception.wrapper.BaseHttpServletRequestWrapper;
import cn.sc.summer.token.service.EncryptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;

import javax.servlet.http.HttpServletRequest;

@Slf4j
public class EncryptRequestWrapper extends BaseHttpServletRequestWrapper {

    public EncryptRequestWrapper(HttpServletRequest request,
                                 EncryptService encryptService) {
        super(request);
        String bodyString = HttpHelper.getBodyString(request);
        super.NEW_BODY = StringEscapeUtils.unescapeJava(encryptService.decrypt(request, bodyString));
    }

}
